#include "StdAfx.h"
#include "MemoryCounter.h"
#include <tchar.h>

unsigned long CMemoryCounter::memory_byte = 0;
CMemoryCounter::CMemoryCounter(void)
{
}


CMemoryCounter::~CMemoryCounter(void)
{
}

void CMemoryCounter::allocate(const unsigned long &size)
{
	memory_byte+=size;
}


void CMemoryCounter::free(const unsigned long &size)
{
	memory_byte-=size;
}
double CMemoryCounter::get_size_memory (const unsigned long &param)
{
	if (param == MC_Bytes)
		return (double)memory_byte;
	else if (param == MC_KBytes)
		return ((double)memory_byte)/1024;
	else if (param == MC_MBytes)
		return ((double)memory_byte)/(1024*1024);
	else if (param == MC_GBytes)
		return ((double)memory_byte)/(1024*1024*1024);
	else
		return 0;
};


std::wstring CMemoryCounter::get_SizeMemoryAsWString (const unsigned long &param)
{
	wchar_t wch_buf [10000];

	if (param == MC_Bytes)
	{
		swprintf_s (wch_buf,_T("%d Bytes"),((unsigned long)get_size_memory(param)));
		return std::wstring(wch_buf);
	}
	else if ((param == MC_KBytes)||(param == MC_MBytes)||(param == MC_GBytes))
	{
		swprintf_s (wch_buf,_T("%.3lf KBytes"),get_size_memory(param));
		return std::wstring(wch_buf);
	}
	else
		return std::wstring(_T("Error parameter"));

	return _T("");
	
}

std::string CMemoryCounter::get_SizeMemoryAsString (const unsigned long &param)
{
	char ch_buf [10000];

	if (param == MC_Bytes)
	{
		sprintf_s (ch_buf,("%d Bytes"),((unsigned long)get_size_memory(param)));
		return std::string(ch_buf);
	}
	else if ((param == MC_KBytes)||(param == MC_MBytes)||(param == MC_GBytes))
	{
		sprintf_s (ch_buf,("%.3lf KBytes"),get_size_memory(param));
		return std::string(ch_buf);
	}
	else
		return std::string(("Error parameter"));

	return ("");
	
}